<template>
  <page-header-wrapper>
    <a-card :bordered="false">
      <div class="gtitle" style="margin-bottom: 20px"><a-icon type="info-circle" style="color: #108ee9" theme="filled"/>级联配置</div>

      <div class="rowtxt">
        <a-row class='rowmb'>
          <a-col :span="4">是否注册到上级平台:</a-col>
          <a-col :span="4">
            <a-radio-group v-model="config.isRegisteSuperiorPlatform" @change="updateconfig('isRegisteSuperiorPlatform',config.isRegisteSuperiorPlatform)">
              <span class="rowspan" style="width: 50%">
                 <a-radio :value="1">是</a-radio>
              </span>
              <span class="rowspan" style="width: 50%">
                 <a-radio :value="0">否</a-radio>
              </span>
            </a-radio-group>
          </a-col>
        </a-row>
        <a-row class='rowmb'>
          <a-col :span="4">上级IP地址:</a-col>
          <a-col :span="4">
            <a-input v-model="config.superiorPlatformUrl" @blur="updateconfig('superiorPlatformUrl',config.superiorPlatformUrl)"></a-input>
          </a-col>
        </a-row>
      </div>

      <div class="gtitle" style="margin-bottom: 20px;margin-top: 20px"><a-icon type="info-circle" style="color: #108ee9" theme="filled"/>级联策略配置</div>
      <div class="rowtxt">
        <a-row class='rowmb'>当本级平台做为一级平台时，需要做以下配置</a-row>
        <a-row class='rowmb'>
          <a-col :span="4">是否允许下级平台注册:</a-col>
          <a-col :span="4">
            <a-radio-group v-model="config.isAllowLowerPlatformRegister" @change="updateconfig('isAllowLowerPlatformRegister',config.isAllowLowerPlatformRegister)">
              <span class="rowspan" style="width: 50%">
                 <a-radio :value="1">是</a-radio>
              </span>
              <span class="rowspan" style="width: 50%">
                 <a-radio :value="0">否</a-radio>
              </span>
            </a-radio-group>
          </a-col>
        </a-row>
        <a-row class='rowmb'>
          <a-col :span="4">是否允许下级平台同步补丁库:</a-col>
          <a-col :span="4">
            <a-radio-group v-model="config.isAllowLowerPlatformSyncPatchLib" @change="updateconfig('isAllowLowerPlatformSyncPatchLib',config.isAllowLowerPlatformSyncPatchLib)">
              <span class="rowspan" style="width: 50%">
                 <a-radio :value="1">是</a-radio>
              </span>
              <span class="rowspan" style="width: 50%">
                 <a-radio :value="0">否</a-radio>
              </span>
            </a-radio-group>
          </a-col>
        </a-row>
        <a-row class='rowmb'>
          <a-col :span="4">允许下级平台同步补丁库的时段:</a-col>
          <a-col :span="8">
            <a-time-picker format="HH:mm:ss" v-model="timefrom" @change="changetimerank()"/>
            ~
            <a-time-picker format="HH:mm:ss" v-model="timeto" @change="changetimerank()"/>
          </a-col>
        </a-row>
      </div>

    </a-card>
  </page-header-wrapper>
</template>

<script>
  import moment from 'moment'
  import { getcascadeconfig,updatecascadeconfig } from '@/api/cascade'
  import {} from '../../utils/constant'
  export default {
    name: 'PatchUpdateManage',
    data() {
      return {
        isopen:'',
        timefrom:'',
        timeto:'',
        config:{}
      }
    },
    mounted() {
      this.$info(
        {
          title:'提示',
          content:'测试Lisence未授权！',
          onOk:()=> {
            this.$router.push({ path: '/overview/overview' })
          },
        }
      )
      this.getconfig()
    },
    methods:{
      getconfig(){
        getcascadeconfig({id:1}).then(res=>{
          if(res.data.allowLowerPlatformSyncTime){
            let time = JSON.parse(res.data.allowLowerPlatformSyncTime)
            this.timefrom = moment(time.startTime,'HH:mm:ss')
            this.timeto = moment(time.endTime,'HH:mm:ss')
          }
          this.config = res.data
        })
      },
      updateconfig(key,value){
        let json = {}
        json.id = 1
        json[key] = value
        updatecascadeconfig(json).then(res=>{})
      },

      changetimerank(){
        if(this.timefrom && this.timeto){
          let j = {
            startTime:moment(this.timefrom).format('HH:mm:ss'),
            endTime:moment(this.timeto).format('HH:mm:ss')
          }
          let json = {}
          json.id = 1
          json.allowLowerPlatformSyncTime = JSON.stringify(j)
          updatecascadeconfig(json).then(res=>{})
        }

      }

    }
  }
</script>

<style lang="less"  scoped>

  .gtitle{
    background-color: #e6f3fc;
    line-height: 40px;
    padding-left: 20px;
    color: #333;
    font-weight: bold;

    i{
      margin-right: 10px;
    }
  }
  .rowtxt,.ant-radio-group{
    line-height: 32px;

  }
  .ant-radio-group{
    width: 100%;
  }
  .rowspan{
    display: inline-block;
    width: 150px;
  }
  .showtxt{
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 0 10px;
    height: 120px;
    overflow-y: auto;
  }
  .rowmb{
    margin-bottom: 10px;
  }
  .blue{
    color: #3366FF;
  }
  .iplist{
    border: 1px solid #ddd;
    padding: 5px;
    min-height: 100px;
    line-height: 30px;
    div:hover{
      background-color: #efefef;
    }
    .icon{
      color: red;
      cursor: pointer;
      line-height: 30px;
      float: right;
      margin-right: 20px;
    }
  }
</style>
